package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.LogMapper;
import com.cskaoyan.model.Log;
import com.cskaoyan.model.LogExample;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.DataVO;
import com.cskaoyan.service.LogService;
import com.cskaoyan.util.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: mall38
 * @description: 日志
 * @author: Lexis
 * @create: 2022-05-05 22:46
 **/
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogMapper logMapper;

    @Override
    public DataVO<Log> query(BaseParamBO param, String name) {
        Integer page = param.getPage();//页码
        Integer limit = param.getLimit();//数据量
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        LogExample logExample = new LogExample();

        logExample.setOrderByClause(param.getSort() + " " + param.getOrder());

        LogExample.Criteria criteria = logExample.createCriteria();
        if (!StringUtil.isEmpty(name)) {
            criteria.andAdminLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);
        List<Log> list = logMapper.selectByExample(logExample);
        PageInfo<Log> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return DataVO.data(total, pages, limit, page, list);
    }
}
